// es6兼容IE
import "babel-polyfill";

// import VConsole from "vconsole";
// new VConsole();

// Vue
import Vue from "vue";
import App from "./App";
// 核心插件
import d2Admin from "@/plugin/d2admin";
// store
import store from "@/store/index";

// 路由设置
import router from "./router";

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

// 核心插件
Vue.use(d2Admin);

new Vue({
  router,
  store,
  watch: {
    // 检测路由变化切换侧边栏内容
    "$route.matched": {
      immediate: true,
      handler(matched) {
        if (matched.length > 0 && matched[0].name !== "login") {
          const savedAside = this.$store.state.d2admin.menu.savedAside;
          const layoutType = this.$store.state.d2admin.layout.layoutType;
          if (savedAside) {
            if (layoutType === 1) {
              const _side = savedAside.find((menu) => menu.path === matched[0].path);
              this.$store.commit("d2admin/menu/asideSet", _side ? _side.children : []);
            } else {
              this.$store.commit("d2admin/menu/asideSet", savedAside);
            }
          }
        }
      },
    },
  },
  mounted() {
    // 用户登录后从数据库加载一系列的设置
    this.$store.dispatch("d2admin/account/load");
    // 初始化全屏监听
    this.$store.dispatch("d2admin/fullscreen/listen");
  },
  render: (h) => h(App),
}).$mount("#app");
